<?php

namespace app\admin\controller;

use think\Controller;
use think\Request;

class Marketing extends Base
{

    public function index()
    {
        //
        $where = array();
        $list = db('group')->where($where)->paginate(5);
        $data = $list->items();
//        dump($data);die();
        $this->assign('list', $list);
        $this->assign('data', $data);
        return $this->fetch();
    }

    public function activity()
    {
        //
        $where = array();
        $list = db('activity')->where($where)->paginate(5);
        $data = $list->items();
//        dump($data);die();
        $this->assign('list', $list);
        $this->assign('data', $data);
        return $this->fetch();
    }
    public function activity_add()
    {
        //
        if (request()->isPost()){
            $inputdate = input();
            $res = db('activity')->insert($inputdate);
            if ($res){
                $this->success('添加成功', url('Marketing/activity'));
            }else{
                $this->error('添加是失败');
            }
        }
        return $this->fetch();
    }
    public function activity_edit($id)
    {
        //
        $res = db('activity')->where('id',$id)->find();
        $this->assign('res', $res);
        if (request()->isPost()){
            $inputdata = input();
            $res = db('activity')->update('id',$inputdata['id']);
            if ($res){
                $this->success('修改成功',url('Marketing/activity'));
            }else{
                $this->error('修改失败');
            }
        }
        return $this->fetch();
    }
    public function activity_delete($id)
    {
        //
        $res = db('activity')->where('id',$id)->delete();
        if ($res){
            $this->success('删除成功', url('Marketing/activity'));
        }else{
            $this->error('删除失败');
        }
        return $this->fetch();
    }
    public function picture(){
        $file = request()->file('file');
        // 移动到框架应用根目录/public/uploads/ 目录下
        $info = $file->move('public/upload/');
        if ($info) {
            $path = 'http://pinguo.com/public/upload/'.$info->getSaveName();
            return json(['code'=>0,'msg'=>'上传成功！','data'=>$path]);
        }else{
            return json(['code'=>1,'msg'=>'上传失败！','data'=>'']);
        }
    }
    public function apply()
    {
        return $this->fetch();
    }

    /**
     * 保存新建的资源
     *
     * @param  \think\Request  $request
     * @return \think\Response
     */

    /**
     * 显示编辑资源表单页.
     *
     * @param  int  $id
     * @return \think\Response
     */


    public function edit($id)
    {
        //
        $res = db('eb_article_category')->where('id',$id)->find();
        $this->assign('res', $res);
        if (request()->isPost()){
            $inputdata = input();
            $res = db('eb_article_category')->update('id',$inputdata['id']);
            if ($res){
                $this->success('修改成功',url('Classify/index'));
            }else{
                $this->error('修改失败');
            }
        }
        return $this->fetch();
    }



    /**
     * 删除指定资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function delete($id)
    {
        //
        $res = db('eb_article_category')->where('id',$id)->delete();
        if ($res){
            $this->success('删除成功', url('Classify/index'));
        }else{
            $this->error('删除失败');
        }
        return $this->fetch();
    }

    public function poster_list(){
        $order = 'sort asc';
        $where = array();
        $list = db('poster')->order($order)->where($where)->paginate(5);
        $data = $list->items();
//        dump($data);die();
        $this->assign('list', $list);
        $this->assign('data', $data);
        return $this->fetch();
    }
    public function poster_add(){
        if (request()->isPost()){
            $inputdate = input();
            $res = db('poster')->insert($inputdate);
            if ($res){
                $this->success('添加成功', url('Marketing/poster_list'));
            }else{
                $this->error('添加失败');
            }
        }
        return $this->fetch();
    }
    public function poster_edit($id){
        $res = db('poster')->where('id',$id)->find();

        $this->assign('res',$res);
        if (request()->isPost()){
            $inputdate = input();
            $res = db('poster')->where('id',$id)->update($inputdate);
            if ($res){
                $this->success('修改成功', url('Marketing/poster_list'));
            }else{
                $this->error('修改失败');
            }
        }else{
            $this->assign( 'find',$res );
            return $this->fetch();
        }

    }
    public function poster_del($id){
        $res = db('poster')->where('id',$id)->delete();
        if ($res){
            $this->success('删除成功', url('Marketing/poster_list'));
        }else{
            $this->error('删除失败');
        }
        return $this->fetch();

    }
    public function phone(){
        $file = request()->file('file');
        // 移动到框架应用根目录/public/uploads/ 目录下
        $info = $file->move('public/upload/');
        if ($info) {
            $path = 'http://pinguo.com/public/upload/'.$info->getSaveName();
            return json(['code'=>0,'msg'=>'上传成功！','data'=>$path]);
        }else{
            return json(['code'=>1,'msg'=>'上传失败！','data'=>'']);
        }
    }


    public function record_list(){
        $where = input();
        $list = db('s_record')->where($where)->paginate('5');
        $data = $list->items();
        $this->assign('list', $list);
        $this->assign('data', $data);
        return $this->fetch();
    }

    public function finance_list(){
        $where = array();
        $list = db('finance')->where($where)->paginate(5);
        $data = $list->items();
//        dump($data);die();
        $this->assign('list', $list);
        $this->assign('data', $data);
        return $this->fetch();
    }

    public function finance_edit($id){
        $res = db('finance')->where('id',$id)->find();

        $this->assign('res',$res);
        if (request()->isPost()){
            $inputdate = input();
            $res = db('finance')->where('id',$id)->update($inputdate);
            if ($res){
                $this->success('修改成功', url('Marketing/finance_list'));
            }else{
                $this->error('修改失败');
            }
        }else{
            $this->assign( 'find',$res );
            return $this->fetch();
        }
    }

    public function tj(){
        if (request()->isPost()){
            $where = input();
            $res = db('tp_con')->insert($where);
            if ($res){
                $this->success('添加成功');
            }else{
                $this->error('添加失败');
            }
        }
        return $this->fetch();
    }
    public function pho(){
        $file = request()->file('file');
        // 移动到框架应用根目录/public/uploads/ 目录下
        $info = $file->move('public/pho/');
        if ($info) {
            $path = 'http://pinguo.com/public/pho/'.$info->getSaveName();
            return json(['code'=>0,'msg'=>'上传成功！','data'=>$path]);
        }else{
            return json(['code'=>1,'msg'=>'上传失败！','data'=>'']);
        }
    }


    public function commission_list(){
        $where = array();
        $list = db('commission')->where($where)->paginate(5);
        $data = $list->items();
//        dump($data);die();
        $this->assign('list', $list);
        $this->assign('data', $data);
        return $this->fetch();
    }





    //充值记录
    public function recharge(){
        $where = array();
        $list = db('recharge')->where($where)->paginate(5);
        $data = $list->items();

        $this->assign('list', $list);
        $this->assign('data', $data);
        return $this->fetch();
    }
    //资金监控
    public function capital(){
        $where = array();
        $list = db('capital')->where($where)->paginate(5);
        $data = $list->items();

        $this->assign('list', $list);
        $this->assign('data', $data);
        return $this->fetch();
    }
    //虚拟货币监控
    public function virtual(){
        $where = array();
        $list = db('virtual')->where($where)->paginate(5);
        $data = $list->items();

        $this->assign('list', $list);
        $this->assign('data', $data);
        return $this->fetch();
    }
}
